package kr.saeildamil.androidstudy_second.cp;

import kr.saeildamil.andrordstudy.second.R;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class ProductList extends Activity {
	ProductDBHelper mHelper;
	Cursor cursor;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch26_productlist);
		
		mHelper = new ProductDBHelper(this, "Product.db", null, 1);
		SQLiteDatabase db = mHelper.getWritableDatabase();
		
		String sql = "select * from product";
		cursor = db.rawQuery(sql, null);
		
		startManagingCursor(cursor);
		
		SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
				android.R.layout.simple_list_item_2, cursor, 
				new String[]{"name" ,"price"}, 
				new int[]{android.R.id.text1,android.R.id.text2});
		
		ListView list = (ListView) findViewById(R.id.list);
		list.setAdapter(adapter);
	}
}












